import requests


class IhrmApi:
    @classmethod
    def ihrm_login_api(cls,login_body):
        login_url = 'http://ihrm2-test.itheima.net/api/sys/login'
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url,headers=login_header,json=login_body)
        return login_resp


    @classmethod
    def add_emp_api(cls,token,add_body):
        add_url = 'http://ihrm2-test.itheima.net/api/sys/user'
        add_header = {"Content-Type": "application/json", "Authorization":token}
        add_resp = requests.post(url=add_url, headers=add_header, json=add_body)
        return add_resp


    @classmethod
    def query_emp_api(cls,emp_id,token):
        query_url = 'http://ihrm2-test.itheima.net/api/sys/user/'+emp_id
        query_header = {"Authorization":token}
        query_resp = requests.get(url=query_url, headers=query_header)
        return query_resp


    @classmethod
    def modify_emp_api(cls,emp_id,token,modify_body):
        modify_url = 'http://ihrm2-test.itheima.net/api/sys/user/'+emp_id
        modify_header = {"Content-Type": "application/json", "Authorization":token}
        modify_resp = requests.put(url=modify_url, headers=modify_header, json=modify_body)
        return modify_resp



    @classmethod
    def del_emp_api(cls,emp_id,token):
        delete_url = 'http://ihrm2-test.itheima.net/api/sys/user/'+emp_id
        delete_header = {"Authorization":token}
        delete_resp = requests.delete(url=delete_url, headers=delete_header)
        return delete_resp

    @classmethod
    def add_dapartment_api(cls,token,add_dep_body):
        add_dep_url = 'http://ihrm2-test.itheima.net/api/company/department'
        add_dep_header = {"Content-Type": "application/json", "Authorization": token}
        add_dep_resp = requests.post(url=add_dep_url, headers=add_dep_header, json=add_dep_body)
        return add_dep_resp


    @classmethod
    def query_department_api(cls,dep_id,token):
        query_dep_url = 'http://ihrm2-test.itheima.net/api/company/department/'+dep_id
        query_dep_header = {"Authorization":token}
        query_dep_resp = requests.get(url=query_dep_url,headers=query_dep_header)
        return query_dep_resp


    @classmethod
    def modify_department_api(cls,dep_id,token,modify_dep_body):
        modify_dep_url = 'http://ihrm2-test.itheima.net/api/company/department/'+dep_id
        modify_dep_header = {"Content-Type": "application/json", "Authorization": token}
        modify_dep_resp = requests.put(url=modify_dep_url,headers=modify_dep_header,json=modify_dep_body)
        return modify_dep_resp


    @classmethod
    def del_department_api(cls,dep_id,token):
        del_dep_url = 'http://ihrm2-test.itheima.net/api/company/department/'+dep_id
        del_dep_header = {"Authorization":token}
        del_dep_resp = requests.delete(url=del_dep_url,headers=del_dep_header)
        return del_dep_resp


if __name__ == '__main__':
    token = 'd208fd19-0b2c-4b23-b0cc-097ff97e225d'
    add_body = {
        "username": "小猪佩奇",
        "mobile": "15912667145",
        "workNumber": "22"
    }
    print(IhrmApi.add_emp_api(token, add_body).json())

